import ServiceBase from '../base';
import * as proxy from '../proxy';
import {GroupModelProxy} from '../proxies/group-model-proxy';
import {MessagePageProxy} from '../proxies/message--page-proxy';

let ACCOUNTS = '/accounts';
let GROUPS = '/groups';

class GroupService extends ServiceBase {
    public getAllGroups = (data) => {
        let promise = super.get({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/groups`,
        });
        return proxy.httpResultProxy(promise, GroupModelProxy);
    };
    public getDeepGroupMembers = (data) => {
        let promise = super.get({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/groups/${data.groupId}/all`,
            params: data.data,
        });
        return proxy.httpResultProxy(promise, MessagePageProxy);
    };
    public getCurrentGroupMembers = (data) => {
        let promise = super.get({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/groups/${data.groupId}/members`,
            params: data.data,
        });
        return proxy.httpResultProxy(promise, MessagePageProxy);
    };
    public moveMembersToGroup = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/groups/${data.groupId}/members`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, GroupModelProxy);
    };
    public addGroup = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/parent/${data.parentId}/group`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, GroupModelProxy);
    };
    public deleteGroup = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/groups/${data.groupId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    public updateGroupInfo = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/groups/${data.groupId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, GroupModelProxy);
    };
    public moveGroup = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/groups/${data.groupId}/move/parent/${
                data.parentId
            }`,
        });
        return proxy.httpResultProxy(promise, GroupModelProxy);
    };
    // account Group
    public getAllAccountGroups = (data) => {
        let promise = super.get({
            url: `${ACCOUNTS}/${data.accountId}/groups`,
        });
        return proxy.httpResultProxy(promise, GroupModelProxy);
    };
    public createAccountGroup = (data) => {
        let promise = super.post({
            url: `${ACCOUNTS}/${data.accountId}/groups`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, GroupModelProxy);
    };
    public updateAccountGroup = (data) => {
        let promise = super.put({
            url: `${ACCOUNTS}/${data.accountId}${GROUPS}/${data.groupId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, GroupModelProxy);
    };
    public deleteGroupTreeNode = (data) => {
        let promise = super.delete({
            url: `${ACCOUNTS}/${data.accountId}${GROUPS}/${data.groupId}`,
        });
        return proxy.httpResultProxy(promise);
    };

    public updateUnGroupMembersGroup = (data) => {
        let promise = super.post({
            url: `${ACCOUNTS}/${data.accountId}${GROUPS}/${data.groupId}/members`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    public updateGroupMembersGroup = (data) => {
        let promise = super.put({
            url: `${ACCOUNTS}/${data.accountId}${GROUPS}/${data.groupId}/members/move`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    public getCloserCompanyByGroupId = (data) => {
        let promise = super.get({
            url: `${ACCOUNTS}/${data.accountId}${GROUPS}/${data.groupId}/closedCorporation`,
            params: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
}

export {GroupService};
